
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author alexandre
 */
@FacesConverter(forClass=Date.class)
public class testeData implements Converter {

    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");

    @Override
    public Object getAsObject(FacesContext fc, UIComponent uic, String string) {
        try {
            Date d = sdf.parse(string);
            return d;
        } catch (ParseException ex) {
            Logger.getLogger(testeData.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    @Override
    public String getAsString(FacesContext fc, UIComponent uic, Object o) {
        return sdf.format((Date) o);
    }
}
